/*
 * $Id: OfferingCampusDao.java 1484 2011-08-16 10:39:12Z jianliu $
 * 
 * Copyright (c) 2001-2008 Accentrix Company Limited. All Rights Reserved.
 * 
 * Accentrix Company Limited. ("Accentrix") retains copyright on all text, source
 * and binary code contained in this software and documentation. Accentrix grants
 * Licensee a limited license to use this software, provided that this copyright
 * notice and license appear on all copies of the software. The software source
 * code is provided for reference purposes only and may not be copied, modified 
 * or distributed.
 * 
 * THIS SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS," WITHOUT ANY WARRANTY OF
 * ANY KIND UNLESS A SEPARATE WARRANTIES IS PURCHASED FROM ACCENTRIX AND REMAINS
 * VALID.  ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ACCENTRIX SHALL NOT BE LIABLE
 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING OR MODIFYING THE
 * SOFTWARE OR ITS DERIVATIVES.
 * 
 * IN NO EVENT WILL ACCENTRIX BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
 * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE
 * USE OF OR INABILITY TO USE SOFTWARE, EVEN IF ACCENTRIX HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */
package com.lightsaber.trade.cloth.dao.programme;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Component;

import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.cloth.entity.programme.BaseProgramme;
import com.lightsaber.trade.cloth.entity.programme.OfferingCampus;

@Component
public class OfferingCampusDao extends BaseDao<OfferingCampus, String> {

    public List<OfferingCampus> findByProgramme(final BaseProgramme programme) {

        eq("programme", programme);
        return list();
    }

    public List<String> distinctOperatingCampusByDiscipline(final String discipline) {

        Map<String, String> map = new HashMap<String, String>();

        String hql = "select distinct oc.operatingCampus from OfferingCampus oc "
                + "where oc.programme.id in (select p.id from Programme p where p.discipline=:discipline)";

        map.put("discipline", discipline);

        Query q = this.createQuery(hql, map);
        return q.list();
    }

    public List<String> distinctOperatingUnitByDiscipline(final String discipline,
            final String operatingCampus) {
        String hql = "select distinct oc.operatingUnit from OfferingCampus oc "
                + " where oc.programme.id in (select p.id from Programme p where p.discipline=:discipline )"
                + "  and oc.operatingCampus=:operatingCampus";
        Map<String, String> map = new HashMap<String, String>();
        map.put("discipline", discipline);
        map.put("operatingCampus", operatingCampus);

        Query q = this.createQuery(hql, map);
        return q.list();
    }
}
